package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.mvp.model.entity.beans.MemberCenterUserInfoBean;


import java.util.List;

public class MemberUpdateLevelRuleAdapter extends BaseQuickAdapter<MemberCenterUserInfoBean.MemberLevelBean, BaseViewHolder> {
    int selectIndex=0;//默认选中
    ItemClickCallback mitemClickCallback;
    boolean isAutoRenew=false;
    public MemberUpdateLevelRuleAdapter(@Nullable List<MemberCenterUserInfoBean.MemberLevelBean> data,ItemClickCallback itemClickCallback) {
        super(R.layout.member_center_update_level_item,data);
        mitemClickCallback=itemClickCallback;
    }

    @Override
    protected void convert(BaseViewHolder helper, MemberCenterUserInfoBean.MemberLevelBean item) {
      helper.<TextView>getView(R.id.member_center_update_level_item_tv1).setText(item.getRuleName());
        helper.<TextView>getView(R.id.member_center_update_level_item_tv2).setText(AppUtil.moneyForat(String.valueOf(item.getDiscountAmount()))+"P");

        if (isAutoRenew)
        {
            helper.<TextView>getView(R.id.member_center_update_level_item_tv3).setText("已优惠"+AppUtil.moneyForat(String.valueOf((item.getAmount()-item.getDiscountAmount())))+"P");
        }else {
            //没选中自动续费
            helper.<TextView>getView(R.id.member_center_update_level_item_tv3).setText(AppUtil.moneyForat(String.valueOf(item.getMonthAmount()))+"P/月");
        }

        if (selectIndex==helper.getPosition())
        {
            helper.<TextView>getView(R.id.member_center_update_level_item_tv1).setTextColor(ArmsUtils.getColor(mContext,R.color.color_F9D35A));
            helper.<TextView>getView(R.id.member_center_update_level_item_tv2).setTextColor(ArmsUtils.getColor(mContext,R.color.color_F9D35A));
            helper.<TextView>getView(R.id.member_center_update_level_item_tv3).setTextColor(ArmsUtils.getColor(mContext,R.color.color_F9D35A));
            helper.<LinearLayout>getView(R.id.member_center_update_level_item_lay).setBackgroundResource(R.drawable.button_yellow_5_bg);

        }else {
            helper.<TextView>getView(R.id.member_center_update_level_item_tv1).setTextColor(ArmsUtils.getColor(mContext,R.color.color_191919));
            helper.<TextView>getView(R.id.member_center_update_level_item_tv2).setTextColor(ArmsUtils.getColor(mContext,R.color.color_ff3a3a));
            helper.<TextView>getView(R.id.member_center_update_level_item_tv3).setTextColor(ArmsUtils.getColor(mContext,R.color.color_191919));
            helper.<LinearLayout>getView(R.id.member_center_update_level_item_lay).setBackgroundResource(R.drawable.box_gray_white_10_bg);
        }
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectIndex=helper.getPosition();
                mitemClickCallback.callback(selectIndex);
                notifyDataSetChanged();
            }
        });
    }

    public boolean isAutoRenew() {
        return isAutoRenew;
    }

    public void setAutoRenew(boolean autoRenew) {
        isAutoRenew = autoRenew;
    }

    public interface ItemClickCallback{
        void callback(int index);
    }
}
